package com.jwork.progress.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jwork.progress.mapper.RepoAdminMapper;
import com.jwork.progress.params.CommonResponse;
import com.jwork.progress.pojo.dto.admin.GetAminListDTO;
import com.jwork.progress.pojo.entity.RepoAdminEntity;
import com.jwork.progress.pojo.vo.repoadmin.RepoAdminVO;
import com.jwork.progress.service.ProducerService;
import com.jwork.progress.service.RepoAminService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

@Service
@RefreshScope
@RequiredArgsConstructor
public class RepoAdminServiceImpl implements RepoAminService {
    private final RepoAdminMapper repoAdminMapper;
    private final ProducerService producerService;

    @Override
    public CommonResponse getAdminList(GetAminListDTO dto) {
        LambdaQueryWrapper<RepoAdminEntity> queryWrapper = new LambdaQueryWrapper<>();
        if (!ObjectUtils.isEmpty(dto.getName())) {
            queryWrapper.like(RepoAdminEntity::getAdminName, "%" + dto.getName() + "%");
        }

        List<RepoAdminEntity> repoAdminList = repoAdminMapper.selectList(queryWrapper);
        List<RepoAdminVO> adminRes = new ArrayList<>();
        for (RepoAdminEntity repoAdminEntity : repoAdminList) {
            RepoAdminVO repoAdminVO = new RepoAdminVO();
            BeanUtils.copyProperties(repoAdminEntity, repoAdminVO);
            adminRes.add(repoAdminVO);
        }
        // 发送测试kaf
//        producerService.send();


        return CommonResponse.success(adminRes);
    }
}
